package com.book.controller.api;

import com.book.service.BookService;
import com.book.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * @Author zzw2000
 * @Date 2022年08月28日 7:42
 * @Description 描述
 */
@Controller
@RequestMapping("/api/admin")
public class AdminApiController {

    @Resource
    private BookService bookService;
    @Resource
    private UserService userService;

    @GetMapping("/delBook")
    public String delBook(@RequestParam("id") int id) {
        bookService.delBook(id);
        return "redirect:/page/admin/book";
    }

    @PostMapping("/addBook")
    public String addBook(@RequestParam("title") String title,
                          @RequestParam("desc") String desc,
                          @RequestParam("price") double price) {
        bookService.addBook(title, desc, price);
        return "redirect:/page/admin/book";
    }

    @PostMapping("/person")
    public String update(@RequestParam("id") Integer id, @RequestParam("password") String password) {
        userService.update(id,password);
        return "redirect:/page/admin/index";
    }
}
